<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>jQuery微博发布案例</title>
    <script src="../jquery/jquery.v3.7.1.js"></script>
    <style>
        a{
            text-decoration: none;
        }
        .box{
            width: 500px;
            height: 600px;
            margin: 0 auto;
            border: 1px solid #000;
            margin-top: 50px;
            position: relative;
        }
        span{
            display: block;
            position: absolute;
            top: 10px;
            left: 20px;
        }
        .txt{
            width: 400px;
            height: 200px;
            position: absolute;
            top: 350px;
            left: 50px;
        }
        .btn{
            position: absolute;
            top: 560px;
            left: 400px;
        }
        ul{
            position: absolute;
            top: 50px;
            left: 50px;
        }
    </style>
</head>
<body>
    <div class="box" id="weibo">
        <span>微博发布</span>
        <textarea name="" class="txt" cols="30" rows="10"></textarea>
        <button class="btn">发布</button>
        <ul></ul>
    </div>
    <script>
        $(function(){
            //点击发布按钮，动态创建一个li，将文本内容添加到 li中,和添加一个删除按钮，把 li标签绑定到 ul上。
            $('.btn').on('click',function(){
                var li = $('<li></li>')
                li.html($('.txt').val() + '<a href="javascript:;">删除</a>');
                $('ul').prepend(li);
                $('.txt').val('');
            });
            //点击删除按钮，删除当前的li
            $('ul').on('click','a',function(){
                $(this).parent().remove();
            })
        })
    </script>
</body>
</html>